package ar.uba.fi.tecnicas.juego;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public abstract class ConfiguracionItems<T> 
{
	public Map<String, T> items;

	protected ConfiguracionItems()
	{
		this.items = new HashMap<String, T>();
		this.LoadData();
	}
	
	protected abstract void LoadData();
	
	public T getItem(String key)
	{
		return this.items.get(key);
	}
	
	public Collection<T> getItems()
	{		
		return this.items.values();		
	}
	
	public T getItem(int index)
	{		
		//T item = ;		
		return (T)this.items.values().toArray()[index];
	}
	
	protected String getElementValue(Element element)
	{
		String value = null;
		
		NodeList list = element.getChildNodes();
		
		if(list.getLength() > 0)
		{
			value = list.item(0).getNodeValue();
		}
		
		return value;
	}
	
	protected Element getChildElement(Element parentElement, String childElementName)
	{
		Element childElement = null;
		
		NodeList childElementNode = parentElement.getElementsByTagName(childElementName);
		
		if(childElementNode.getLength() > 0)
		{
			childElement = (Element) childElementNode.item(0);
		}
		
		return childElement;
	}	
}
